<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
if(isset($_REQUEST['ten']) && isset($_REQUEST['winW'])){
	$w=$_REQUEST['winW']*90/100;
	$mm=$w."px";
	$c1=$w*10/100;
	$c2=$w*20/100;
	$c4=200;
	$c3=$w-($c1+$c2+$c4);
	include '../sort/sorclass.php';
	$ten=$_REQUEST['ten'];
	if('datetime'==$ten){
		$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		$sl=count($_SESSION['mrs']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}
				?>
			</table>
			<?php 
		}
	}else if('name'==$ten){
		if(isset($_SESSION['mname']) && count($_SESSION['mname'])>0){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mname']=array();
			$connection1 = mysql_connect("1.234.20.151", "cam", "5678" ) ;
			mysql_select_db("elicam", $connection1);
			mysql_query("set names 'utf8'");
			$sql="select t.id,c.name,t.car_datetime,t.carnumber,c.host,t.filename,t.isReg 
			from carnum t ,configcamera c 
			where t.id=c.id and t.car_datetime>='2011-01-01 00:00:00' 
			and t.car_datetime<='2013-01-23 23:59:59' 
			and t.id in ( 1013 ) order by c.name desc ";
			$kq=mysql_query($sql,$connection1);
			$sl=mysql_num_rows($kq);
			if($sl>0){
				$ngu=0;
				while($r=mysql_fetch_array($kq)){
					$ob= new sort();
					$ob->newsort($r['id'], $r['name'], $r['car_datetime'], $r['carnumber'], $r['filename'], $r['host'], $r['isReg']);
					$_SESSION['mname'][$ngu++]=$ob;
				}
			}
			mysql_close($connection1);
		}
		$sl=count($_SESSION['mname']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}
				?>
			</table>
			<?php 
		}
	}else if('carnumber'==$ten){
		if(isset($_SESSION['mcarnum']) && count($_SESSION['mcarnum'])>0){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mcarnum']=array();
			$connection11 = mysql_connect("1.234.20.151", "cam", "5678" ) ;
			mysql_select_db("elicam", $connection11);
			mysql_query("set names 'utf8'");
			$sql="select t.id,c.name,t.car_datetime,t.carnumber,c.host,t.filename,t.isReg 
			from carnum t ,configcamera c 
			where t.id=c.id and t.car_datetime>='2011-01-01 00:00:00' 
			and t.car_datetime<='2013-01-23 23:59:59' 
			and t.id in ( 1013 ) order by t.carnumber desc ";
			$kq=mysql_query($sql,$connection11);
			$sl=mysql_num_rows($kq);
			if($sl>0){
				while($r=mysql_fetch_array($kq)){
					$ob= new sort();
					$ob->newsort($r['id'], $r['name'], $r['car_datetime'], $r['carnumber'], $r['filename'], $r['host'], $r['isReg']);
					$_SESSION['mcarnum'][]=$ob;
				}
			}
			mysql_close($connection11);
		}
		$sl=count($_SESSION['mcarnum']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mcarnum'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php	
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mcarnum'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php		
					}
				}
				?>
			</table>
			<?php 	
		}
	}
}
?>